package pl.freetimetool.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "accountRole")
public class AccountRole implements Serializable {

	private static final long serialVersionUID = 5008138264149238409L;

	public AccountRole() {
		this.setRole("ROLE_ANONYMOUS");
	}

	public AccountRole(final String role) {
		this.setRole(role);
	}

	public AccountRole(final Object role) {
		this.setRole(role.toString());
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	Integer id;

	public Integer getId() {
		return this.id;
	}

	public void setId(final Integer roleId) {
		this.id = roleId;
	}

	@Basic
	String role;

	public String getRole() {
		return this.role;
	}

	public void setRole(final String role) {
		this.role = role;
	}

	@ManyToOne(targetEntity = Account.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	// @JoinColumn(name = "id", nullable = true)
	Account account;

	public Account getAccount() {
		return this.account;
	}

	public void setAccount(final Account account) {
		this.account = account;
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj instanceof AccountRole) {
			return ((AccountRole) obj).getRole().equals(this.getRole());
		}
		return false;
	}

	@Override
	public String toString() {
		return "AccountRole: " + this.role;
	}
}
